package org.mspring.platform.security.service;

import org.mspring.platform.security.dao.RoleTreeItemDao;
import org.mspring.platform.security.entity.RoleTreeItem;
import org.mspring.platform.security.entity.RoleTreeItemPK;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Gao Youbo
 * @since 2014年3月8日
 */
@Service
@Transactional
public class RoleTreeItemService {

    @Autowired
    private RoleTreeItemDao roleTreeItemDao;

    /**
     * 创建角色和树形菜单之间的关联
     *
     * @param roleId
     * @param treeItems
     */
    public void createRoleTreeItem(long roleId, String... treeItems) {
        for (String treeItem : treeItems) {
            RoleTreeItem roleTreeItem = new RoleTreeItem(new RoleTreeItemPK(roleId, treeItem));
            roleTreeItemDao.insert(roleTreeItem);
        }
    }

    /**
     * 删除角色和树形菜单之间的关联
     *
     * @param roleId
     * @param treeItems
     */
    public void deleteRoleTreeItem(long roleId, String... treeItems) {
        for (String treeItem : treeItems) {
            roleTreeItemDao.delete(new RoleTreeItemPK(roleId, treeItem));
        }
    }

    /**
     * 清空该表数据
     */
    public void clear() {
        roleTreeItemDao.clear();
    }
}
